package com.edu.exit_;

/**
 * 线程退出
 */
public class ThreadExit_ {

    public static void main(String[] args) throws InterruptedException {

        T t = new T();
        t.start();
        Thread.sleep(5000);

        t.setLoop(false);
    }
}

class T extends Thread {
    private boolean loop = true;
    int i;

    @Override
    public void run() {
        while (loop) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(i++);
        }
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}
